package com.example.smartcitydemo.ui.job

import android.os.Bundle
import com.blankj.utilcode.util.ToastUtils
import com.example.smartcity_jscs.network.ResultStates.Resource
import com.example.smartcitydemo.R
import com.example.smartcitydemo.base.BaseActivity
import com.example.smartcitydemo.bean.ResumePostBean
import com.example.smartcitydemo.databinding.ActivityNewJobBinding
import com.example.smartcitydemo.viewModel.job.WorkViewModel

/**
 * @PACKAGE_NAME: com.example.smartcitydemo.ui.job
 * @NAME: Caleb.F
 * @DATE: 2021/11/19 15:02
 * @Email: 1919796283@qq.com
 */
class NewJobActivity : BaseActivity<ActivityNewJobBinding>(R.layout.activity_new_job) {
    private val workViewModel: WorkViewModel by lazy {
        WorkViewModel()
    }

    override fun addObserver(contentView: ActivityNewJobBinding) {
        workViewModel.addResumeResult.observe(this) {
            when (it) {
                is Resource.Success -> {
                    ToastUtils.showShort("新建成功")

                    finish()
                }
                is Resource.Failure -> {
                    ToastUtils.showShort("$it")
                }
            }
        }
    }

    override fun initData() {

    }

    override fun initView(contentView: ActivityNewJobBinding, savedInstanceState: Bundle?) {
        contentView.resumeToolbar.tvContent.text= "新增简历"
        val inputList = listOf(
            contentView.textInputLayout11,
            contentView.textInputLayout22,
            contentView.textInputLayout33,
            contentView.textInputLayout44,
            contentView.textInputLayout55,
            contentView.textInputLayout66,
        )
        contentView.btnResumeAdd.setOnClickListener {
            val map = inputList.map { it.editText?.text?.trim().toString() }
            if (map.all { it.isNotEmpty() }) {
                val bean = ResumePostBean(
                    map[0],
                    map[1],
                    map[2],
                    map[3],
                    map[4],
                    map[5]
                )
                workViewModel.addPersonResume(bean)
            } else {
                ToastUtils.showShort("请输入完整内容")
            }
        }
    }
}